package com.celesea.auth.user.entity;

import com.celesea.auth.user.v1.controller.request.PostRequest;
import com.celesea.framework.entity.BusEntity;
import com.celesea.framework.util.PinyinKit;
import com.celesea.framework.util.Version;
import org.springframework.beans.BeanUtils;

import javax.persistence.Column;
import javax.persistence.Table;


@Version
@Table(name = "user")
public class User extends BusEntity {

    @Column(name = "`name`", columnDefinition = "名称")
    private String name;
    @Column(name = "`py`", columnDefinition = "拼音")
    private String py;
    @Column(name = "`account`", columnDefinition = "账号")
    private String account;
    @Column(name = "`password`", columnDefinition = "密码")
    private String password;
    @Column(name = "`email`", columnDefinition = "邮箱")
    private String email;
    @Column(name = "`mobile`", columnDefinition = "手机")
    private String mobile;
    @Column(name = "`company`", columnDefinition = "所属公司")
    private String company;
    @Column(name = "`dept_id`", columnDefinition = "所属部门")
    private String deptId;
    @Column(name = "`dept_name`", columnDefinition = "所属名称")
    private String deptName;
    @Column(name = "`grade_id`", columnDefinition = "职级")
    private String gradeId;
    @Column(name = "`grade_name`", columnDefinition = "职级名称")
    private String gradeName;
    @Column(name = "`leader_id`", columnDefinition = "上级Id")
    private String leaderId;
    @Column(name = "`leader_name`", columnDefinition = "上级名称")
    private String leaderName;
    @Column(name = "`status_flag`", columnDefinition = "在职状态：[0：离职，1：正常]", nullable = false)
    private Byte statusFlag;
    @Column(name = "`perm_flag`", columnDefinition = "授权查看状态：[0：否，1：是]", nullable = false)
    private Byte permFlag;

    public User() {
    }

    public User(PostRequest request) {
        BeanUtils.copyProperties(request, this);
        this.setPy(PinyinKit.getPinyinFirst(this.getName()));
        if (request.getDept() != null) {
            this.setDeptId(request.getDept().getId());
            this.setDeptName(request.getDept().getName());
        }
        if (request.getGrade() != null) {
            this.setGradeId(request.getGrade().getId());
            this.setGradeName(request.getGrade().getName());
        }
        if (request.getLeader() != null) {
            this.setLeaderId(request.getLeader().getId());
            this.setLeaderName(request.getLeader().getName());
        }
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPy() {
        return py;
    }

    public void setPy(String py) {
        this.py = py;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getDeptId() {
        return deptId;
    }

    public void setDeptId(String deptId) {
        this.deptId = deptId;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public String getGradeId() {
        return gradeId;
    }

    public void setGradeId(String gradeId) {
        this.gradeId = gradeId;
    }

    public String getGradeName() {
        return gradeName;
    }

    public void setGradeName(String gradeName) {
        this.gradeName = gradeName;
    }

    public Byte getStatusFlag() {
        return statusFlag;
    }

    public void setStatusFlag(Byte statusFlag) {
        this.statusFlag = statusFlag;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getLeaderId() {
        return leaderId;
    }

    public void setLeaderId(String leaderId) {
        this.leaderId = leaderId;
    }

    public String getLeaderName() {
        return leaderName;
    }

    public void setLeaderName(String leaderName) {
        this.leaderName = leaderName;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public Byte getPermFlag() {
        return permFlag;
    }

    public void setPermFlag(Byte permFlag) {
        this.permFlag = permFlag;
    }
}

